// 最长公共前缀

strs = ["flower","flow","flight"]

var longestCommonPrefix = function(strs) {
    let first = strs[0]
    let minlen = Infinity
    for (let i = 0; i < strs.length; i++) {
        if (strs[i].length == 0) {
            return ''
        }

      minlen = Math.min(toStrLongestCommonPrefix(first, strs[i]), minlen)
      console.log(minlen);
    }

    return first.slice(0, minlen)
 


function toStrLongestCommonPrefix(s, t) {
        let i = 0, j = 0, cnt = 0
        while(i < s.length && j < t.length) { // 遍历整个字符串
            if(s[i] === t[j]) {
                cnt++
            } else {
                return cnt
            }
            i++
            j++
        }
        return cnt
}
}
longestCommonPrefix(strs)